<template>
	<view class="merchant_container" v-if="merchantId && merchant.id">
		<view class="section-title">注册店铺</view>
		<view class="merchant-card">
			<view class="merchant-header">
				<view class="merchant-basic">
					<text class="shop-name">{{merchant.name}}</text>
					<text class="merchant-name">{{merchant.merchantName}}</text>
					<view class="merchant-status" :class="{'active': merchant.status === 1}">
						{{merchant.status === 1 ? '营业中' : '已停业'}}
					</view>
				</view>
			</view>

			<view class="merchant-info">
				<view class="address-row">
					<uv-icon name="map" size="32" color="#007AFF"></uv-icon>
					<text
						class="address-text">{{merchant.province}}{{merchant.city}}{{merchant.district}}{{merchant.street}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "MerchantInfoEasyCard",
		data() {
			return {
				merchant: {},
			};
		},

		props: {
			merchantId: Number
		},

		methods: {
			async fetchMerchantInfo() {
				if (!this.merchantId) {
					return;
				}
				try {
					const merchant = await this.$http.post(
						`/auth/wechat/user/binding/merchant?merchantId=${this.merchantId}`);

					this.merchant = merchant;
				} catch (e) {
					console.error(e);
				}
			}
		},

		mounted() {
			this.fetchMerchantInfo();
		}
	}
</script>

<style lang="scss" scoped>
	@import 'MerchantInfoEasyCard.scss';
</style>